package com.etooling.framework.utils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.text.DecimalFormat;

public class Keep2Format extends JsonSerializer<Number> {

    private DecimalFormat df = new DecimalFormat("0.00");

    @Override
    public void serialize(Number value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (value != null) {
            jsonGenerator.writeNumber(df.format(value.doubleValue()));
        }
    }
}
